function block_index=blockindex(T,hor)
block_length=hor+1;
block_index_matrix=ones(block_length,T);
block_index_matrix(1,:)=unidrnd(T,1,T);
block_index_matrix_cs=cumsum(block_index_matrix,1);
block_index_matrix_cs(block_index_matrix_cs>T)=NaN;
block_index_matrix_reshape=reshape(block_index_matrix_cs,[block_length*T,1]);
nan_ind = ~isnan(block_index_matrix_reshape);
block_index_matrix_reshape=block_index_matrix_reshape(nan_ind);
block_index=block_index_matrix_reshape(1:T,:);
end